package com.kyivmohyla.kma2.client.view.refbook;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import com.kyivmohyla.kma2.client.presenter.refbook.NewItemTreeGridViewPresenter;

import java.util.List;

public class NewItemTreeGridView extends Composite implements NewItemTreeGridViewPresenter.Display {
    private static NewItemTreeGridViewUiBinder ourUiBinder = GWT.create(NewItemTreeGridViewUiBinder.class);
    @UiField
    protected TextBox name;
    @UiField
    protected CheckBox isParent;
    @UiField
    protected ListBox category;
    @UiField
    protected TextBox description;
    @UiField
    protected Button save;
    @UiField
    protected Button cancel;

    public NewItemTreeGridView() {
        initWidget(ourUiBinder.createAndBindUi(this));
    }

    @Override
    public HasClickHandlers getSaveButton() {
        return save;
    }

    @Override
    public HasClickHandlers getCancelButton() {
        return cancel;
    }

    @Override
    public CheckBox getIsParent() {
        return isParent;
    }

    @Override
    public HasText getName() {
        return name;
    }

    @Override
    public HasText getDescription() {
        return description;
    }

    @Override
    public ListBox getCategory() {
        return category;
    }

    @Override
    public void displayCategories(List<String> values) {
        category.addItem("");
        for (String item : values) {
            category.addItem(item);
        }
    }

    public Widget asWidget() {
        return this;
    }

    interface NewItemTreeGridViewUiBinder extends UiBinder<Widget, NewItemTreeGridView> {
    }
}